/*
 * TabbedPaneDemo.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.demos.swingset;

import com.cute4j.swing.Component;
import com.cute4j.swing.Container;
import com.cute4j.swing.ImageIcon;
import com.cute4j.swing.Label;
import com.cute4j.swing.RadioButton;
import com.cute4j.swing.ScrollPane;
import com.cute4j.swing.SelectableGroup;
import com.cute4j.swing.TabbedPane;
import com.cute4j.swing.events.ActionEvent;
import com.cute4j.swing.events.ActionListener;
import com.cute4j.swing.layouts.formlayout.CellConstraints;
import com.cute4j.swing.layouts.formlayout.FormLayout;

/**
 * Demonstration of the TabbedPane class.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class TabbedPaneDemo extends DemoModule {

// Private Fields. -------------------------------------------------------------

  private TabbedPane tabPane;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new TabbedPaneDemo object.
   */
  public TabbedPaneDemo() {
    super("TabbedPane Demo", "Demonstration of the TabbedPane class.");
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  protected Component buildDemoComponent() {
    FormLayout layout = new FormLayout(
              "p:g, 20dlu, r:p, 6dlu, p, 4dlu, p, 4dlu, p, 4dlu, p, 20dlu, p:g",
              "p, 24dlu, f:220dlu");
    Container panel = new Container(layout);
    panel.setInsets(16, 16, 16, 16);
    CellConstraints cc = new CellConstraints();

    panel.add(new Label("Tab Placement:"), cc.xy(3, 1));
    RadioButtonActionListener actionListener = new RadioButtonActionListener();
    SelectableGroup sg = new SelectableGroup();
    RadioButton radioButton = new RadioButton("Top");
    radioButton.addActionListener(actionListener);
    radioButton.setSelected(true);
    sg.add(radioButton);
    panel.add(radioButton, cc.xy(5, 1));
    radioButton = new RadioButton("Left");
    radioButton.addActionListener(actionListener);
    sg.add(radioButton);
    panel.add(radioButton, cc.xy(7, 1));
    radioButton = new RadioButton("Bottom");
    radioButton.addActionListener(actionListener);
    sg.add(radioButton);
    panel.add(radioButton, cc.xy(9, 1));
    radioButton = new RadioButton("Right");
    radioButton.addActionListener(actionListener);
    sg.add(radioButton);
    panel.add(radioButton, cc.xy(11, 1));

    tabPane = new TabbedPane();
    Label enabledTab = new Label("Enabled Tab");
    enabledTab.setHorizontalAlignment(Label.CENTER);
    tabPane.addTab("Enabled", enabledTab);
    tabPane.addTab("Disabled", new Label("Tab 2"));
    tabPane.setEnabledAt(1, false);
    ImageIcon icon = new ImageIcon(loadResource(
                               "resources/images/tabbedpane/GreenTeaCup.png"));
    Label iconTab = new Label("Tab with Icon and ToolTip");
    iconTab.setHorizontalAlignment(Label.CENTER);
    tabPane.addTab("Icon", icon, iconTab, "Icon");
        tabPane.addTab("Disabled Icon", icon, new Label("Icon"));
    tabPane.setEnabledAt(3, false);
    panel.add(tabPane, cc.xyw(2, 3, 11));

    return new ScrollPane(panel);
  }

// Inner Classes. --------------------------------------------------------------

  /**
   * RadioButton ActionListener.
   */
  class RadioButtonActionListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      String actionCommand = e.getActionCommand();
      if ("Top".equals(actionCommand)) {
        tabPane.setTabPlacement(TabbedPane.TOP);
      } else if ("Left".equals(actionCommand)) {
        tabPane.setTabPlacement(TabbedPane.LEFT);
      } else if ("Bottom".equals(actionCommand)) {
        tabPane.setTabPlacement(TabbedPane.BOTTOM);
      } else if ("Right".equals(actionCommand)) {
        tabPane.setTabPlacement(TabbedPane.RIGHT);
      }
    }
  }

// Main Method. ----------------------------------------------------------------

  /**
   * Starts demo as standalone application.
   *
   * @param args the application arguments
   */
  public static void main(String[] args) {
    new TabbedPaneDemo().show();
  }

}
